//
//  NSString+StringCustom.m
//  ADYiZhiYu
//
//  Created by 晓 on 2017/10/31.
//  Copyright © 2017年 com.idolmedia. All rights reserved.
//

#import "NSString+StringCustom.h"
//#import "ADCommonMethods.h"
#import <sys/utsname.h>

@implementation NSString (StringCustom)

+ (NSMutableAttributedString *)contenetStr:(NSString *)contentStr rangeStr:(NSString *)rangeStr contentFont:(UIFont*)contentFont rangeFont:(UIFont*)rangeFont contentColor:(UIColor *)contentColor rangeColor:(UIColor *)rangeColor
{
    NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:contentStr];
    
    //总体的颜色和大小
    NSRange range = NSMakeRange(0, [noteStr string].length);
    [noteStr addAttribute:NSForegroundColorAttributeName value:contentColor range:range];
    [noteStr addAttribute:NSFontAttributeName value:contentFont range:range];
    
    //设置的部分的颜色和大小
    NSRange rangeRange = NSMakeRange([[noteStr string] rangeOfString:rangeStr].location, [[noteStr string] rangeOfString:rangeStr].length);
    [noteStr addAttribute:NSForegroundColorAttributeName value:rangeColor range:rangeRange];
    [noteStr addAttribute:NSFontAttributeName value:rangeFont range:rangeRange];

    return noteStr;
}

//加行间距
+ (NSMutableAttributedString *)contenetStr:(NSString *)contentStr rangeStr:(NSString *)rangeStr contentFont:(UIFont*)contentFont rangeFont:(UIFont*)rangeFont contentColor:(UIColor *)contentColor rangeColor:(UIColor *)rangeColor WithSpace:(float)space{
    
    NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:contentStr];
    //行间距
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
    paragraphStyle.lineBreakMode=NSLineBreakByWordWrapping;
    [paragraphStyle setLineSpacing:space];
    [noteStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [contentStr length])];
    
    //总体的颜色和大小
    NSRange range = NSMakeRange(0, [noteStr string].length);
    [noteStr addAttribute:NSForegroundColorAttributeName value:contentColor range:range];
    [noteStr addAttribute:NSFontAttributeName value:contentFont range:range];
    
    //设置的部分的颜色和大小
    NSRange rangeRange = NSMakeRange([[noteStr string] rangeOfString:rangeStr].location, [[noteStr string] rangeOfString:rangeStr].length);
    [noteStr addAttribute:NSForegroundColorAttributeName value:rangeColor range:rangeRange];
    [noteStr addAttribute:NSFontAttributeName value:rangeFont range:rangeRange];
    return noteStr;
}


//添加中划线
+ (NSMutableAttributedString *)underlineContenetStr:(NSString *)contentStr rangeStr:(NSString *)rangeStr contentFont:(UIFont*)contentFont rangeFont:(UIFont*)rangeFont contentColor:(UIColor *)contentColor rangeColor:(UIColor *)rangeColor{
    NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:contentStr];
    
    //总体的颜色和大小
    NSRange range = NSMakeRange(0, [noteStr string].length);
    [noteStr addAttribute:NSForegroundColorAttributeName value:contentColor range:range];
    [noteStr addAttribute:NSFontAttributeName value:contentFont range:range];
    
    //设置的部分的颜色和大小
    NSRange rangeRange = NSMakeRange([[noteStr string] rangeOfString:rangeStr].location, [[noteStr string] rangeOfString:rangeStr].length);
    
    [noteStr addAttributes:@{NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle], NSBaselineOffsetAttributeName : @(NSUnderlineStyleSingle)} range:rangeRange];
    
    NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [noteStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:range];
    
    [noteStr addAttribute:NSForegroundColorAttributeName value:rangeColor range:rangeRange];
    [noteStr addAttribute:NSFontAttributeName value:rangeFont range:rangeRange];
    
    return noteStr;
}


+(TYTextContainer *)stringWithContentStr:(NSString *)contentStr contentColor:(UIColor *)contentColor contentFont:(CGFloat)contentFont rangeStr:(NSString *)rangeStr rangBackgroundColor:(UIColor *)rangBackgroundColor rangeFont:(CGFloat)rangeFont rangeCorner:(CGFloat)rangeCorner rangeRectCorner:(UIRectCorner)rangRectCorner withViewWidth:(CGFloat )viewWidth
{
    NSMutableAttributedString *att = [[NSMutableAttributedString alloc]initWithString:contentStr];
    
    //总体的颜色和大小
    NSRange range = NSMakeRange(0, [att string].length);
    [att addAttribute:NSForegroundColorAttributeName value:contentColor range:range];
    [att addAttribute:NSFontAttributeName value:FONT_SIZE(contentFont) range:range];
    
    TYTextContainer *textContainer = [[TYTextContainer alloc]init];
    textContainer.attributedText = att;
    textContainer.font = FONT_SIZE(contentFont);
    //设置高度
    textContainer.numberOfLines = 10;
    
    if (![ADCommonMethods isBlankString:rangeStr]) {
        // 整体设置属性
        NSMutableArray *textFieldArray = [NSMutableArray array];
        UILabel *textlabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, [NSString labelAutoCalculateRectWith:rangeStr WithFont:FONT_SIZE(rangeFont) MaxSize:CGSizeMake(150, CGFLOAT_MAX)].width+8,13)];
        textlabel.textColor = [UIColor whiteColor];
        textlabel.backgroundColor = rangBackgroundColor;

    //UIRectCornerBottomLeft | UIRectCornerTopLeft | UIRectCornerTopRight
        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:textlabel.bounds byRoundingCorners:rangRectCorner cornerRadii:CGSizeMake(rangeCorner, rangeCorner)];
        CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
        maskLayer.frame = textlabel.bounds;
        maskLayer.path = maskPath.CGPath;
        textlabel.layer.mask = maskLayer;
        
        textlabel.text = rangeStr;
        textlabel.textAlignment = NSTextAlignmentCenter;
        textlabel.font = FONT_SIZE(rangeFont);
        TYViewStorage *viewStorage = [[TYViewStorage alloc]init];
        viewStorage.range = NSMakeRange(0, 0);
        viewStorage.view = textlabel;
        viewStorage.drawAlignment = TYDrawAlignmentCenter;
        [textFieldArray addObject:viewStorage];
        [textContainer addTextStorageArray:textFieldArray];
        
    }
    
    textContainer = [textContainer createTextContainerWithTextWidth:viewWidth];
    return textContainer;
}

//根据字计算Label的长度
+ (CGSize)labelAutoCalculateRectWith:(NSString*)text WithFont:(UIFont *)font MaxSize:(CGSize)maxSize
{
//    NSMutableParagraphStyle* paragraphStyle = [[NSMutableParagraphStyle alloc]init];
//    paragraphStyle.lineBreakMode=NSLineBreakByWordWrapping;
    NSDictionary* attributes =@{NSFontAttributeName:font};
    CGSize labelSize = [text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil].size;
    labelSize.height=ceil(labelSize.height);
    labelSize.width=ceil(labelSize.width);
    return labelSize;
}

//加行间距计算Label的长度
+(CGSize)labelAutoCalculateRectWith:(NSString*)text WithFont:(UIFont *)font MaxSize:(CGSize)maxSize WithSpace:(float)space
{
    NSMutableParagraphStyle* paragraphStyle = [[NSMutableParagraphStyle alloc]init];
    paragraphStyle.lineBreakMode=NSLineBreakByWordWrapping;
    [paragraphStyle setLineSpacing:space];
    NSDictionary* attributes =@{NSFontAttributeName:font,NSParagraphStyleAttributeName:paragraphStyle.copy};
    CGSize labelSize = [text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading|NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil].size;
    labelSize.height=ceil(labelSize.height);
    labelSize.width=ceil(labelSize.width);
    
    return labelSize;
}

- (float)widthWithFont:(UIFont *)font limitHeight:(float)height
{
    NSDictionary *attribute = @{NSFontAttributeName: font};
    CGSize size = [self boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, height)
                                     options:NSStringDrawingUsesLineFragmentOrigin
                                  attributes:attribute
                                     context:nil].size;
    return size.width;
}

- (float)heightWithFont:(UIFont *)font limitWidth:(float)width
{
    NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:8];
    NSDictionary *attribute = @{NSFontAttributeName: font,NSParagraphStyleAttributeName:paragraphStyle};
    CGSize size = [self boundingRectWithSize:CGSizeMake(width, CGFLOAT_MAX)
                                     options:NSStringDrawingUsesLineFragmentOrigin
                                  attributes:attribute
                                     context:nil].size;
    return size.height;
}


+(NSMutableAttributedString *)contentString:(NSString *)str
{
    
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    NSMutableAttributedString *setString = [[NSMutableAttributedString alloc] initWithString:str];
    [setString  addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [str length])];
    
    return setString;
}

+ (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString {
    if (jsonString == nil) {
        return nil;
    }
    
    NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
    NSError *err;
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData
                                                        options:NSJSONReadingMutableContainers
                                                          error:&err];
    if(err) {
        NSLog(@"json解析失败：%@",err);
        return nil;
    }
    return dic;
}


+ (NSString*)dictionaryToJson:(NSDictionary *)dic

{
    NSError *parseError = nil;
    
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&parseError];
    
    return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    
}


+ (NSString *)arrayToJSONString:(NSArray *)array

{
    NSError *error = nil;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:array options:NSJSONWritingPrettyPrinted error:&error];
    NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    return jsonString;
}


+ (NSString*)removeFloatAllZero:(NSString*)string
{
    NSString * testNumber = string;
    NSString * outNumber = [NSString stringWithFormat:@"%@",@(testNumber.floatValue)];
    return outNumber;
}
//获取手机型号
+ (NSString *)iphoneType {
    
    struct utsname systemInfo;
    
    uname(&systemInfo);
    
    NSString *platform = [NSString stringWithCString:systemInfo.machine encoding:NSASCIIStringEncoding];
    
    if ([platform isEqualToString:@"iPhone3,1"]) return @"iPhone 4";
    
    if ([platform isEqualToString:@"iPhone3,2"]) return @"iPhone 4";
    
    if ([platform isEqualToString:@"iPhone3,3"]) return @"iPhone 4";
    
    if ([platform isEqualToString:@"iPhone4,1"]) return @"iPhone 4S";
    
    if ([platform isEqualToString:@"iPhone5,1"]) return @"iPhone 5";
    
    if ([platform isEqualToString:@"iPhone5,2"]) return @"iPhone 5";
    
    if ([platform isEqualToString:@"iPhone5,3"]) return @"iPhone 5c";
    
    if ([platform isEqualToString:@"iPhone5,4"]) return @"iPhone 5c";
    
    if ([platform isEqualToString:@"iPhone6,1"]) return @"iPhone 5s";
    
    if ([platform isEqualToString:@"iPhone6,2"]) return @"iPhone 5s";
    
    if ([platform isEqualToString:@"iPhone7,1"]) return @"iPhone 6 Plus";
    
    if ([platform isEqualToString:@"iPhone7,2"]) return @"iPhone 6";
    
    if ([platform isEqualToString:@"iPhone8,1"]) return @"iPhone 6s";
    
    if ([platform isEqualToString:@"iPhone8,2"]) return @"iPhone 6s Plus";
    
    if ([platform isEqualToString:@"iPhone8,4"]) return @"iPhone SE";
    
    if ([platform isEqualToString:@"iPhone9,1"]) return @"iPhone 7";
    
    if ([platform isEqualToString:@"iPhone9,2"]) return @"iPhone 7 Plus";
    
    if ([platform isEqualToString:@"iPhone10,1"]) return @"iPhone 8";
    
    if ([platform isEqualToString:@"iPhone10,4"]) return @"iPhone 8";
    
    if ([platform isEqualToString:@"iPhone10,2"]) return @"iPhone 8 Plus";
    
    if ([platform isEqualToString:@"iPhone10,5"]) return @"iPhone 8 Plus";
    
    if ([platform isEqualToString:@"iPhone10,3"]||(int)SCREEN_HEIGHT==812) return @"iPhone X";
    
    if ([platform isEqualToString:@"iPhone10,6"]||(int)SCREEN_HEIGHT==812) return @"iPhone X";
    
    else{
        return @"no";
    }
    
    return platform;
}

//判断图片类型
+ (NSString *)contentTypeForImageData:(NSData *)data {
    uint8_t c;
    [data getBytes:&c length:1];
    switch (c) {
        case 0xFF:
            return @"jpeg";
        case 0x89:
            return @"png";
        case 0x47:
            return @"gif";
        case 0x49:
            
        case 0x4D:
            return @"tiff";
        case 0x52:
            if ([data length] < 12) {
                return nil;
            }
            NSString *testString = [[NSString alloc] initWithData:[data subdataWithRange:NSMakeRange(0, 12)] encoding:NSASCIIStringEncoding];
            if ([testString hasPrefix:@"RIFF"] && [testString hasSuffix:@"WEBP"]) {
                return @"webp";
            }
            return nil;
    }
    return nil;
}


+ (NSString *)encodeToPercentEscapeString: (NSString *) input

{
    NSString *outputStr =
    
    (__bridge NSString *)CFURLCreateStringByAddingPercentEscapes(
                                                                 
                                                                 NULL, /* allocator */
                                                                 
                                                                 (__bridge CFStringRef)input,
                                                                 
                                                                 NULL, /* charactersToLeaveUnescaped */
                                                                 
                                                                 (CFStringRef)@"!*'();:@&=+$,/?%#[]",
                                                                 
                                                                 kCFStringEncodingUTF8);
    
    return outputStr;
    
}

//解码
+ (NSString *)decodeFromPercentEscapeString:(NSString *)input

{

    NSMutableString *outputStr = [NSMutableString stringWithString:input];
    
    [outputStr replaceOccurrencesOfString:@"+"
     
                               withString:@""
     
                                  options:NSLiteralSearch
     
                                    range:NSMakeRange(0,[outputStr length])];
    
    return [outputStr stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
}

//时间戳转换
+ (NSString *)timeBeforeInfoWithString:(NSTimeInterval)timeIntrval{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
    //获取此时时间戳长度
    NSTimeInterval nowTimeinterval = [[NSDate date] timeIntervalSince1970];
    int timeInt = nowTimeinterval - timeIntrval; //时间差
    
    int year = timeInt / (3600 * 24 * 30 *12);
    int month = timeInt / (3600 * 24 * 30);
    int day = timeInt / (3600 * 24);
    int hour = timeInt / 3600;
    int minute = timeInt / 60;
    if (year > 0) {
        return [NSString stringWithFormat:@"%d年前",year];
    }else if(month > 0){
        return [NSString stringWithFormat:@"%d个月前",month];
    }else if(day > 0){
        return [NSString stringWithFormat:@"%d天前",day];
    }else if(hour > 0){
        return [NSString stringWithFormat:@"%d小时前",hour];
    }else if(minute > 0){
        return [NSString stringWithFormat:@"%d分钟前",minute];
    }else{
        return [NSString stringWithFormat:@"刚刚"];
    }
}

//时间转时间戳
+(NSInteger)timeSwitchTimestamp:(NSString *)formatTime{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
    [formatter setTimeZone:timeZone];
    NSDate *dateStr = [formatter dateFromString:formatTime];
    NSInteger timeSp = [[NSNumber numberWithDouble:[dateStr timeIntervalSince1970]] integerValue];
    return timeSp;
}

//时间戳转时间
+ (NSString *)getTimeFromTimestamp:(NSString *)formatTime{
    NSTimeInterval interval = [formatTime doubleValue] / 1000.0;
    NSDate *myDate = [NSDate dateWithTimeIntervalSince1970:interval];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
    NSString *timeStr = [formatter stringFromDate:myDate];
    return timeStr;
}

//获取当前年份、月份、日期
+(NSInteger)getMonthTimeFromTimestamp:(NSString *)formatTime{
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"YYYY-MM-dd"];
    NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
    [formatter setTimeZone:timeZone];
    NSDate *dateStr = [formatter dateFromString:formatTime];
    NSInteger timeSp = [[NSNumber numberWithDouble:[dateStr timeIntervalSince1970]] integerValue];

    NSDate *myDate = [NSDate dateWithTimeIntervalSince1970:timeSp];
    NSCalendar *calendar = [NSCalendar currentCalendar];
//    unsigned unitFlags = NSCalendarUnitMonth;
//    NSDateComponents *components = [calendar components:unitFlags fromDate:myDate];
//    NSInteger iCurMonth = [components month];  //当前的月份
    
    NSRange range = [calendar rangeOfUnit:NSCalendarUnitDay
                                   inUnit: NSCalendarUnitMonth
                                  forDate:myDate];//当前月份总天数
    return range.length;
}

- (NSString *)URLEncodedString{
    
    NSString *unencodedString = self;
    NSString *encodedString = (NSString *)
    CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
                                                              (CFStringRef)unencodedString,
                                                              NULL,
                                                              (CFStringRef)@"!*'();:@&=+$,/?%#[]",
                                                              kCFStringEncodingUTF8));
    
    return encodedString;
}

- (NSString *)URLDecodedString{
    
    NSString *result = [(NSString *)self stringByReplacingOccurrencesOfString:@"+" withString:@" "];
    return [result stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
}

//获取当前时间 YYYY-MM-dd HH:mm:ss
+(NSString*)getCurrentTimesAndFormat:(NSString *)format{
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    
    // ----------设置你想要的格式,hh与HH的区别:分别表示12小时制,24小时制
    
    [formatter setDateFormat:format];
    
    //现在时间,你可以输出来看下是什么格式
    
    NSDate *datenow = [NSDate date];
    
    //----------将nsdate按formatter格式转成nsstring
    
    NSString *currentTimeString = [formatter stringFromDate:datenow];
    
//    NSLog(@"currentTimeString =  %@",currentTimeString);
    
    return currentTimeString;
    
}

+(NSString *)getJiDu
{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"MM"];
    NSDate *datenow = [NSDate date];
    NSString *currentTimeString = [formatter stringFromDate:datenow];
    if ([currentTimeString integerValue]>=1&&[currentTimeString integerValue]<=3) {
        return @"1";
    }else if ([currentTimeString integerValue]>=4&&[currentTimeString integerValue]<=6){
        return @"2";
    }else if ([currentTimeString integerValue]>=7&&[currentTimeString integerValue]<=9){
        return @"3";
    }else{
        return @"4";
    }
}

//去除null
+(NSString *)passNullForString:(id)str
{
    str = [NSString stringWithFormat:@"%@",str];
    if ([self isBlankString:str]) {
        return @"";
    }else{
        return str;
    }
}


//检测字符串是否为空
+ (BOOL)isBlankString:(NSString *)string{
    
    if (string == nil) {
        return YES;
    }
    if (string == NULL) {
        return YES;
    }
    if ([string isKindOfClass:[NSNull class]]) {
        return YES;
    }
    if ([string isEqualToString:@"(null)"]) {
        return YES;
    }
    if ([string isEqualToString:@"<null>"]) {
        return YES;
    }
    if ([string isEqualToString:@""]) {
        return YES;
    }
    if ([[string stringByTrimmingCharactersInSet:
          [NSCharacterSet whitespaceCharacterSet]] length]==0) {
        return YES;
    }
    return NO;
}


//js的encodeURIComponent 
+ (NSString *)URLEncodedString:(NSString *)str {
    NSString *encodedString = (NSString *)
    CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
                                                              (CFStringRef)str,
                                                              NULL,
                                                              (CFStringRef)@"!*'();:@&=+$,/?%#[]",
                                                              kCFStringEncodingUTF8));
    return encodedString;
}

//webview
+(NSString *)webLoadStrForContentStr:(NSString *)contentString
{
    NSString *contentStr = [contentString stringByReplacingOccurrencesOfString:@"#000000" withString:@"#525151"];
    NSString *headerStr = [NSString stringWithFormat:@"<head><style>img{max-width:%fpx !important;}table{max-width:%fpx !important;}</style></head>",SCREEN_WIDTH,SCREEN_WIDTH];
    contentStr = [NSString stringWithFormat:@"%@%@",headerStr,contentStr];
    NSString *htmls = contentString;
    
    htmls = [NSString stringWithFormat:@"<html> \n"
             "<head> \n"
             "<style type=\"text/css\"> \n"
             "body {font-size:15px;color:#525151;}\n"
             "</style> \n"
             "</head> \n"
             "<body>"
             "<script type='text/javascript'>"
             "window.onload = function(){\n"
             "var $img = document.getElementsByTagName('img');\n"
             "for(var p in  $img){\n"
             " $img[p].style.width = 'auto';\n"
             "$img[p].style.height ='auto'\n"
             "}\n"
             "}"
             "</script>%@"
             "</body>"
             "</html>",contentStr];
    
    NSString *htmls1 = [NSString stringWithFormat:@"<div id=\"webview_content_wrapper\">%@</div>", htmls];
    return htmls1;
}

//字符串改颜色
+(NSMutableAttributedString *)contentString:(NSString *)contentStr subString:(NSString *)subStr subColor:(UIColor *)subColor subFont:(UIFont *)subFont;
{
    if ([contentStr rangeOfString:@"null"].location!=NSNotFound) {
        subStr = @"";
    }
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    if ([contentStr rangeOfString:@"\n"].location!=NSNotFound) {
        paragraphStyle.lineSpacing = 4;
    }
    NSMutableAttributedString *setString = [[NSMutableAttributedString alloc] initWithString:contentStr];
    [setString  addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [contentStr length])];
    
    NSRange range = NSMakeRange([contentStr rangeOfString:subStr].location, [contentStr rangeOfString:subStr].length);
    [setString  addAttribute:NSForegroundColorAttributeName value:subColor range:range];
    [setString  addAttribute:NSFontAttributeName value:subFont range:range];
    
    return setString;
}

//当前时间戳
+(NSString *)getNowTimeTimestamp{
    
//    NSDateFormatter *formatter = [[NSDateFormatter alloc] init] ;
//
//    [formatter setDateStyle:NSDateFormatterMediumStyle];
//
//    [formatter setTimeStyle:NSDateFormatterShortStyle];
//
//    [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss SSS"]; // ----------设置你想要的格式,hh与HH的区别:分别表示12小时制,24小时制
//
//    //设置时区,这个对于时间的处理有时很重要
//
//    NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
//
//    [formatter setTimeZone:timeZone];
//
//    NSDate *datenow = [NSDate date];//现在时间,你可以输出来看下是什么格式
//
//    NSString *timeSp = [NSString stringWithFormat:@"%ld", (long)[datenow timeIntervalSince1970]*1000];
    
    double currentTime =  [[NSDate date] timeIntervalSince1970]*1000;
    
    NSString *timeSp = [NSString stringWithFormat:@"%.0f",currentTime];
    

    return timeSp;
    
}

@end
